<?php
  class DataRenderer {
  	public static function ViewAsList($q, $id = null) {
      $str = "<ul class=\"list\">";
      while ($r = mysql_fetch_assoc($q)) {
        $str .= "<li class=\"list-item ".($id==$r["ID"]?"sel":"")."\"><a href=\"?t=".$r["ID"]."\">".$r["Title"]."</a></li>";
      }
      $str .= "</ul>";
      return $str;
		}

  	public static function ViewHeaders($q) {
		}

  	public static function ViewThread($q, $id = null) {
		}

    public static function ViewAsTable($q, $o = null) {
      $str = "<table class=\"view\">";
      while ($r = mysql_fetch_assoc($q)) {
        foreach ($r as $k => $v) if ($k != "ID") {
          $str .= "<tr><td class=\"key\">$k:</td><td class=\"value\">$v</td></tr>";
        }
      }
      $str .= "</table>";
      return $str;
    }
    public static function BrowseAsTable($q, $o = null) {
      /* SUPPORTED OPTIONS
       * $o["deleteColumn"] = izpiše delete column
       * $o["selectedValue"] = vrstica bo označena, če se ujema z vrednostjo v prvem stolpcu
       * $o["mouseover"] = vrstica spremeni class na mouseover
       * */
      $rowCount = 0;
      $str = "<table class=\"selectable\">";
      while ($r = mysql_fetch_assoc($q)) {
        if ($rowCount++ % 25 == 0) {
          $str .= "<tr class=\"frst\">";
            foreach ($r as $k => $v) {
              $tdStyle = ($k == "ID") ? 'display:none;' : '';
              $str .= "<td style=\"$tdStyle\">$k</td>";
            }
            if ($o["deleteColumn"])
                $str .= "<td>&nbsp;</td>";
            $str .= "</tr>\r\n";
        }
        $colCount = 0;
        $class = (isset($o["selectedValue"]) and $r["ID"] == $o["selectedValue"]) ? ' selected' : '';
        $mouseover = (isset($o["mouseover"])) ? "onmouseover=\"$(this).addClass('mouseover');\" onmouseout=\"$(this).removeClass('mouseover');\"" : '';
        $str .= "<tr class=\"$class\" $mouseover>";
        foreach ($r as $k => $v) {
          $colCount++;
          $tdStyle = ($k == "ID") ? 'display:none;' : '';
          $str .= "<td style=\"$tdStyle\" class=\"c$colCount\">$v</td>";
        }
        if ($o["deleteColumn"])
          $str .= "<td><a title=\"Brisanje\" class=\"delete\" onclick=\"Terinda.Narocila_kupcev.DeleteG(".$r["Stevilka"].");\">x</a></td>";
        $str .= "</tr>\r\n";
      }
      $str .= "</table>";
      return $str;
    }
  }
?>